ALMaSS  1.0
The Animal, Landscape and Man Simulation System
MovementMap.h
Go to the documentation of this file.
1 /*
2 *******************************************************************************************************
3 Copyright (c) 2011, Christopher John Topping, University of Aarhus
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without modification, are permitted provided
7 that the following conditions are met:
8 
9 Redistributions of source code must retain the above copyright notice, this list of conditions and the
10 following disclaimer.
11 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
12 the following disclaimer in the documentation and/or other materials provided with the distribution.
13 
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
15 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
17 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
18 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
19 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 ********************************************************************************************************
23 */
36 //---------------------------------------------------------------------------
37 #ifndef MovementMapH
38 #define MovementMapH
39 
40 //------------------------------------------------------------------------------
41 
42 
43 //------------------------------------------------------------------------------
44 class TAnimal;
45 
51 {
52  public:
56  int GetMapValue(unsigned x, unsigned y);
57  void SetMapValue(unsigned x, unsigned y, unsigned value);
58  void SetMapValue0(unsigned x, unsigned y);
59  void SetMapValue1(unsigned x, unsigned y);
60  void SetMapValue2(unsigned x, unsigned y);
61  void SetMapValue3(unsigned x, unsigned y);
62  MovementMap(Landscape * L, int spref);
63  ~MovementMap();
64  protected:
66  void Init(int spref);
67 };
68 //------------------------------------------------------------------------------
69 
75 {
76  public:
80  int GetMapValue(unsigned x, unsigned y);
81  void SetMapValue(unsigned x, unsigned y, unsigned value);
82  void ClearMapValue(unsigned x, unsigned y);
85  protected:
87  void Init();
88 };
89 //------------------------------------------------------------------------------
90 
91 
96 template <class a_type> class IDMap
97 {
98 public:
99  vector<a_type> m_TheMap;
100  int maxx;
101  int maxy;
102  a_type GetMapValue(unsigned x, unsigned y) {
103  return m_TheMap[x + (maxx*y)];
104  }
105  void SetMapValue(unsigned x, unsigned y, a_type p) {
106  m_TheMap[x + (maxx*y)] = p;
107  }
108  void ClearMapValue(unsigned x, unsigned y) {
109  m_TheMap[x + (maxx*y)] = NULL;
110  }
112  maxx = L->SupplySimAreaWidth();
113  maxy = L->SupplySimAreaHeight();
114  m_TheMap.resize(maxx*maxy);
115  for (int y = 0; y<maxy; y++) {
116  for (int x = 0; x<maxx; x++) {
117  SetMapValue(x, y, NULL);
118  }
119  }
120  }
121  ~IDMap() {
122  ;
123  }
124 };
125 //------------------------------------------------------------------------------
126 
127 
132 class IDMapScaled : public IDMap<TAnimal*>
133 {
134 public:
135  int m_scale;
136  TAnimal* GetMapValue(unsigned a_x, unsigned a_y) {
138  a_x /= m_scale;
139  a_y /= m_scale;
140  return m_TheMap[a_x + (maxx*a_y)];
141  }
142  void SetMapValue(unsigned a_x, unsigned a_y, TAnimal* p) {
144  a_x /= m_scale;
145  a_y /= m_scale;
146  m_TheMap[a_x + (maxx*a_y)] = p;
147  }
148  void ClearMapValue(unsigned a_x, unsigned a_y){
150  a_x /= m_scale;
151  a_y /= m_scale;
152  m_TheMap[a_x + (maxx*a_y)] = NULL;
153  }
154  IDMapScaled(Landscape * L, int a_gridsize);
155  ~IDMapScaled();
156 };
157 //------------------------------------------------------------------------------
158 
159 
160 //---------------------------------------------------------------------------
161 #endif
unsigned int uint32
Definition: ALMaSS_Setup.h:34
Used to map locations of animals in space.
Definition: MovementMap.h:97
int maxx
Definition: MovementMap.h:100
vector< a_type > m_TheMap
Definition: MovementMap.h:99
int maxy
Definition: MovementMap.h:101
IDMap(Landscape *L)
Definition: MovementMap.h:111
void SetMapValue(unsigned x, unsigned y, a_type p)
Definition: MovementMap.h:105
~IDMap()
Definition: MovementMap.h:121
void ClearMapValue(unsigned x, unsigned y)
Definition: MovementMap.h:108
a_type GetMapValue(unsigned x, unsigned y)
Definition: MovementMap.h:102
Used to map locations of animals in space.
Definition: MovementMap.h:133
int m_scale
Definition: MovementMap.h:135
void ClearMapValue(unsigned a_x, unsigned a_y)
Definition: MovementMap.h:148
IDMapScaled(Landscape *L, int a_gridsize)
Definition: MovementMap.cpp:497
void SetMapValue(unsigned a_x, unsigned a_y, TAnimal *p)
Definition: MovementMap.h:142
TAnimal * GetMapValue(unsigned a_x, unsigned a_y)
Definition: MovementMap.h:136
~IDMapScaled()
Definition: MovementMap.cpp:513
The landscape class containing all environmental and topographical data.
Definition: landscape.h:113
int SupplySimAreaHeight(void)
Definition: landscape.h:1637
int SupplySimAreaWidth(void)
Definition: landscape.h:1632
Movement maps are used for rapid computing of animal movement.
Definition: MovementMap.h:75
uint32 * m_TheMap
Definition: MovementMap.h:77
Landscape * m_ALandscape
Definition: MovementMap.h:86
void Init()
Definition: MovementMap.cpp:442
MovementMap16(Landscape *L)
Definition: MovementMap.cpp:423
void SetMapValue(unsigned x, unsigned y, unsigned value)
Definition: MovementMap.cpp:456
uint32 maxx
Definition: MovementMap.h:78
int GetMapValue(unsigned x, unsigned y)
Definition: MovementMap.cpp:486
void ClearMapValue(unsigned x, unsigned y)
Definition: MovementMap.cpp:476
~MovementMap16()
Definition: MovementMap.cpp:435
uint32 maxy
Definition: MovementMap.h:79
Movement maps are used for rapid computing of animal movement.
Definition: MovementMap.h:51
Landscape * m_ALandscape
Definition: MovementMap.h:65
uint32 maxx
Definition: MovementMap.h:54
uint32 maxy
Definition: MovementMap.h:55
void SetMapValue(unsigned x, unsigned y, unsigned value)
Definition: MovementMap.cpp:341
~MovementMap()
Definition: MovementMap.cpp:62
int GetMapValue(unsigned x, unsigned y)
Definition: MovementMap.cpp:409
void SetMapValue0(unsigned x, unsigned y)
Definition: MovementMap.cpp:361
void SetMapValue1(unsigned x, unsigned y)
Definition: MovementMap.cpp:372
uint32 * m_TheMap
Definition: MovementMap.h:53
void Init(int spref)
Definition: MovementMap.cpp:69
MovementMap(Landscape *L, int spref)
Definition: MovementMap.cpp:50
void SetMapValue2(unsigned x, unsigned y)
Definition: MovementMap.cpp:384
void SetMapValue3(unsigned x, unsigned y)
Definition: MovementMap.cpp:397
The base class for all ALMaSS animal classes.
Definition: PopulationManager.h:205